/*
 * TopPanel.java
 *
 * Created on __DATE__, __TIME__
 */

package Windows;

import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import DBUtil.CNN;
import Tools.IMG;
import Tools.JLabelStyle;
import XML.XMLNode;

/**
 * 
 * @author __USER__
 */
public class TopPanel extends PicPanel {

	// GEN-BEGIN:variables
	// Variables declaration - do not modify
	public final javax.swing.JLabel SeachButton;

	private javax.swing.JLabel jLTitle;

	public final javax.swing.JLabel jLabel2 = new javax.swing.JLabel();

	public final javax.swing.JLabel jlLogo;
	public final javax.swing.JTextField jtfKeys = new javax.swing.JTextField();
	// End of variables declaration//GEN-END:variables
	/** Creates new form TopPanel */
	public TopPanel(Image img) {
		super(img);
		SeachButton = new JLabelStyle(IMG.m, IMG.en, IMG.pr);
		jlLogo = new JLabelStyle(IMG.ii, IMG.ii2, IMG.ii2);

		initComponents();

		jlLogo.addMouseListener(AboutWindow.getAboutWindow());

		jLTitle.setText(CNN.getConfig().GetPathValue("User:Title").toString());
		jLTitle.setFont(new Font("Default", 0, 24));
		jLTitle.setForeground(new Color(255, 255, 255));

		JLabelStyle.setStyle(jLabel2);

		jLabel2.setText("搜索资源");
		SeachButton.setIcon(IMG.search); // NOI18N
		// SeachButton.setBorderPainted(false);//不会只边框
		// SeachButton.invalidate();//使其无效
		// SeachButton.setBackground(Color.black);
		jtfKeys.setForeground(new java.awt.Color(51, 153, 255));
		jtfKeys.setText("请输入关键字");
		jtfKeys.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));
		jtfKeys.setCaretColor(new java.awt.Color(255, 102, 102));

		jtfKeys.addFocusListener(new FocusListener() {

			@Override
			public void focusGained(FocusEvent arg0) {
				// TODO Auto-generated method stub
				if (jtfKeys.getText().equals("请输入关键字")) {
					jtfKeys.setText("");
					jtfKeys.setForeground(Color.BLUE);
				}
			}

			@Override
			public void focusLost(FocusEvent arg0) {
				// --失去焦点
				if (jtfKeys.getText().equals("")) {
					jtfKeys.setText("请输入关键字");
					jtfKeys.setForeground(Color.GRAY);
				}
			}
		});
		jtfKeys.addKeyListener(new KeyListener() {

			@Override
			public void keyPressed(KeyEvent arg0) {
				// TODO Auto-generated method stub

			}

			@Override
			public void keyReleased(KeyEvent e) {
				// TODO Auto-generated method stub
				// System.out.println(e.getKeyCode());
				if (e.getKeyCode() == 10)
					FastSeatch();
			}

			@Override
			public void keyTyped(KeyEvent arg0) {
				// TODO Auto-generated method stub

			}
		});
		SeachButton.addMouseListener(new MouseListener() {

			@Override
			public void mouseClicked(MouseEvent e) {
				// TODO Auto-generated method stub
				FastSeatch();
			}

			// --鼠标进入事件处理
			@Override
			public void mouseEntered(MouseEvent e) {

			}

			// --鼠标离开事件
			@Override
			public void mouseExited(MouseEvent e) {

			}

			@Override
			public void mousePressed(MouseEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void mouseReleased(MouseEvent e) {
				// TODO Auto-generated method stub

			}

		});

	}
	/**
	 * 快速搜索
	 */
	private void FastSeatch() {
		// TODO Auto-generated method stub
		XMLNode xf = new XMLNode(null, "seach");
		xf.put("keys", jtfKeys.getText());
		xf.put("minsize", "-1"); // 任意文件大小
		xf.put("maxsize", "-1"); // 任意文件大小
		xf.put("type", "*"); // 任务文件类型
		if (xf.get("keys").length() > 0) {
			MainWindows.getInstance().mpanel.getSeachp().addSeach(xf);// 添加搜索任务
			jtfKeys.setText("");
		}
	}
	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jLTitle = new javax.swing.JLabel();

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
				layout.createSequentialGroup().addComponent(jlLogo).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE).addGap(18, 18, 18).addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jtfKeys, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(10, 10, 10).addComponent(SeachButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap()));
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(31, 31, 31).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel2).addComponent(jtfKeys, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))).addComponent(jlLogo).addGroup(layout.createSequentialGroup().addGap(25, 25, 25).addComponent(SeachButton, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLTitle, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)));
	}// </editor-fold>
		// GEN-END:initComponents

}